package com.haocang.szgm.activity.comm;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;

import com.umeng.message.PushAgent;

import net.tsz.afinal.FinalActivity;

public abstract class CommFullActivity extends FinalActivity {

	protected static Context mContext;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		//TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		mContext = this;
		initWindows();
		setContentView(getLayoutResourceId());
	}

	/**
	 * 获取布局文件
	 * @return
	 */
	protected abstract int getLayoutResourceId();



	@SuppressLint("NewApi")
	private void initWindows() {
		Window window = getWindow();
		int color = getResources().getColor(android.R.color.transparent);
		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
			window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
					| WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
			window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
					| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
					| View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
			window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
			//设置状态栏颜色
			window.setStatusBarColor(color);
			//设置导航栏颜色
			window.setNavigationBarColor(color);
			ViewGroup contentView = findViewById(android.R.id.content);
			View childAt = contentView.getChildAt(0);
			if (childAt != null) {
				childAt.setFitsSystemWindows(true);
			}
		} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
			//透明状态栏
			window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
			//透明导航栏
			window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
			//设置contentview为fitsSystemWindows
			ViewGroup contentView = findViewById(android.R.id.content);
			View childAt = contentView.getChildAt(0);
			if (childAt != null) {
				childAt.setFitsSystemWindows(true);
			}
			//给statusbar着色
			View view = new View(mContext);
			view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, getStatusBarHeight()));
			view.setBackgroundColor(color);
			contentView.addView(view);
		}
	}
	/**
	 * 获取导航栏高度
	 * @return 导航栏高度
	 */
	public static int getNavigationBarHeight() {
		int resourceId = mContext.getResources().getIdentifier("navigation_bar_height", "dimen", "android");
		return mContext.getResources().getDimensionPixelSize(resourceId);
	}

	/**
	 * 获取状态栏高度
	 * @return 状态栏高度
	 */
	private static int getStatusBarHeight() {
		// 获得状态栏高度
		int resourceId = mContext.getResources().getIdentifier("status_bar_height", "dimen", "android");
		return mContext.getResources().getDimensionPixelSize(resourceId);
	}

	protected  void ToastShow(String msg){
		Toast.makeText(mContext, msg, Toast.LENGTH_SHORT).show();
	}

}
